//
//  ChildrenStoryTableCell.m
//  HappyBaby
//
//  Created by 华哥 on 15/11/24.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "ChildrenStoryTableCell.h"
#import "Define.h"


@interface ChildrenStoryTableCell ()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *artistLabel;
@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic, strong) UIView *view;
//@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
//@property (weak, nonatomic) IBOutlet UILabel *artist;
//@property (weak, nonatomic) IBOutlet UILabel *countLabel;
//@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
//@property (weak, nonatomic) IBOutlet UILabel *artistLabel;
//@property (weak, nonatomic) IBOutlet UILabel *countLabel;
//@property (weak, nonatomic) IBOutlet UIView *view;

@end

@implementation ChildrenStoryTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        float scaleX = kScreenWidth / 375;
        float scaleY = kScreenHeight / 667;
//        NSArray *arrayOfViews = [[NSBundle mainBundle]loadNibNamed:@"ChildrenStoryCell" owner:self options:nil];
//        
//        if (arrayOfViews.count < 1)
//        {
//            return nil;
//        }
//        if (![[arrayOfViews objectAtIndex:0]isKindOfClass:[UITableViewCell class]])
//        {
//            return nil;
//        }
//        self = [arrayOfViews objectAtIndex:0];
        self.view = [[UIView alloc]initWithFrame:CGRectMake(self.frame.origin.x + 4 * scaleX, self.frame.origin.y + 2 * scaleY, kScreenWidth - 8 * scaleX, (60 - 4) * scaleY)];
        
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(50 * scaleX, 3 * scaleY, 230 * scaleY, 30 * scaleY)];
        self.nameLabel.font = [UIFont systemFontOfSize:15 * scaleX weight:1];
        
        
        self.artistLabel = [[UILabel alloc]initWithFrame:CGRectMake(50 * scaleX, self.nameLabel.height + 3 * scaleY, 80 * scaleX, 20 * scaleY)];
        self.artistLabel.font = [UIFont systemFontOfSize:10 * scaleX weight:1];
        
        self.orderLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * scaleX, 10 * scaleY, 40 * scaleX, 40 * scaleY)];
        self.orderLabel.font = [UIFont systemFontOfSize:22 * scaleX weight:0.5];
        self.orderLabel.textColor = [UIColor colorWithRed:42 / 255.0 green:116 / 255.0 blue:255 / 255.0 alpha:1];
        self.orderLabel.textAlignment = NSTextAlignmentCenter;        
        
        // 小的Image
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(130 * scaleX, self.nameLabel.height + self.nameLabel.y, 15 * scaleX, 15 * scaleY)];
        imageView.image = [UIImage imageNamed:@"xinxing"];
        
        self.countLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.x + imageView.width, imageView.y, 50 * scaleX, 15 * scaleX)];
        self.countLabel.font = [UIFont systemFontOfSize:10 * scaleX weight:1];
        self.countLabel.textAlignment = NSTextAlignmentCenter;
        
        [self.view addSubview:_nameLabel];
        [self.view addSubview:_artistLabel];
        [self.view addSubview:_orderLabel];
        [self.view addSubview:_countLabel];
        [self.view addSubview:imageView];
        
        self.view.layer.cornerRadius = 5;
        self.view.backgroundColor = [UIColor whiteColor];
        self.contentView.backgroundColor = [UIColor colorWithRed:184 / 255.0 green:241 / 255.0 blue:251 / 255.0 alpha:1];
        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self.contentView addSubview:_view];
    }
    return self;
}

- (void)setModel:(ChildrenStoryDetail *)model
{
    _model = model;
    self.nameLabel.text = model.name;
    self.artistLabel.text = model.artist;
    NSString *detail = [NSString stringWithFormat:@"%ld万", (NSInteger)model.playcnt / 10000];
    self.countLabel.text = detail;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
